package com.nuoniu.sibanyun.service.finance.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.finance.VAccountingSearchProgramme;
import com.nuoniu.sibanyun.mapper.finance.VAccountingSearchProgrammeMapper;
import com.nuoniu.sibanyun.service.erp.IErpAccountService;
import com.nuoniu.sibanyun.service.finance.IVAccountingSearchProgrammeService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 科目总账查询方案表 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2021-05-08
 */
@Service
public class VAccountingSearchProgrammeServiceImpl extends ServiceImpl<VAccountingSearchProgrammeMapper, VAccountingSearchProgramme> implements IVAccountingSearchProgrammeService {

    @Autowired
    private IErpAccountService accountService;

    @Override
    public void saveProgramme(VAccountingSearchProgramme searchProgramme) {
        if(searchProgramme.getId() == null) {
            UserInfo userInfo = UserThreadLocal.get();
            searchProgramme.setCreateUserId(userInfo.getUserId());
            searchProgramme.setCompanyId(userInfo.getCompanyId());
            searchProgramme.setAccountId(accountService.getCurrentAccountId());
        }

        saveOrUpdate(searchProgramme);
    }

    @Override
    public List<VAccountingSearchProgramme> getList(Integer type) {
        QueryWrapper wrapper = new QueryWrapper();
        UserInfo userInfo = UserThreadLocal.get();
        wrapper.eq("type", type);
        wrapper.eq("create_user_id", userInfo.getUserId());
        return list(wrapper);
    }
}
